package com.awenhui.demo.controller;

import com.awenhui.demo.model.PersonDto;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RequestMapping("/thymeleaf")
@Controller
public class ThymeleafController {

    @GetMapping("index")
    public String index(Model model) {
        model.addAttribute("name", "于新方");
        model.addAttribute("users", Arrays.asList("张三","李四","王五","赵六"));
        return "hello";
    }

    @GetMapping("hello2")
    public String hello2(Map<String,Object> map)
    {
        map.put("name","于新方");
        map.put("age","18");
        map.put("users",Arrays.asList("zhangsan","lisi","wangwu"));
        List<PersonDto> persons=new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            PersonDto personDto=new PersonDto();
            personDto.setName("惠惠"+i);
            personDto.setAge(16+i);
            personDto.setSex(i%2==0);
            persons.add(personDto);
        }
        map.put("persons",persons);
        return  "hello2";
    }
    @GetMapping("login")
    public String login()
    {
return "login";
    }
}
